#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+7;
int T;
int n,m,L,V;
int v[maxn],a[maxn],p[maxn],d[maxn];
int maxp=0;
bool t[3007][3007];
void work1(){
	int ans=0;
	for(int i=1;i<=n;i++){
		if(v[i]>V&&d[i]<=maxp)ans++;
	}
	if(ans!=0)cout<<ans<<" "<<m-1<<endl;
	else cout<<ans<<" "<<m<<endl;
}
int main(){
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>T;
	while(T--){
		cin>>n>>m>>L>>V;
		for(int i=1;i<=n;i++){
			cin>>d[i]>>v[i]>>a[i];
		}
		for(int i=1;i<=m;i++){
			cin>>p[i];
			maxp=max(maxp,p[i]);
		}
		work1();
	}
	return 0;
}
